www.gusucode.com > VC 串口通讯_数据库存取例子-源码程序 > VC 串口通讯_数据库存取例子-源码程序/code/Modem3/LinkButton.cpp
//Download by http://www.NewXing.com // LinkButton.cpp : implementation file // #include "stdafx.h" #include "Modem3.h" #include "LinkButton.h" //#include "CModem3Dlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CLinkButton CLinkButton::CLinkButton() { m_brush1.CreateSolidBrush(RGB(0,245,0)); m_brush2.CreateSolidBrush(RGB(220, 220, 220)); m_updown=TRUE; } CLinkButton::~CLinkButton() { if (fUnderline.GetSafeHandle()) fUnderline.DeleteObject(); } BEGIN_MESSAGE_MAP(CLinkButton, CButton) //{{AFX_MSG_MAP(CLinkButton) ON_WM_LBUTTONDOWN() ON_WM_LBUTTONUP() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CLinkButton message handlers void CLinkButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { // 获取一个CDC指针 CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC); //定义按钮区域并初始化 CRect rect(lpDrawItemStruct->rcItem); int iObk = pDC->SetBkMode(TRANSPARENT); //初始化按钮状态 UINT state = lpDrawItemStruct->itemState; CFont * pOldFont = NULL; CString strText; GetWindowText(strText); if (button_flag==0) { pDC->SetBkColor(RGB(225,255,255)); pDC->FillRect(rect,&m_brush2); // pDC->Draw3dRect(rect,::GetSysColor(COLOR_BTNHIGHLIGHT),::GetSysColor(COLOR_BTNSHADOW)); pDC->DrawText(strText, rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE); } else if(button_flag==1) { pDC->Draw3dRect(rect,RGB(0,0,0),RGB(0,0,0)); //字体颜色 pDC->SetTextColor(RGB(0,0,0)); pDC->FillRect(rect,&m_brush1); // pDC->Draw3dRect(rect,::GetSysColor(COLOR_BTNHIGHLIGHT),::GetSysColor(COLOR_BTNSHADOW)); pDC->DrawText(strText, rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE); } //加下画线(也可以用其他字体) if(m_updown) pDC->Draw3dRect(rect,::GetSysColor(COLOR_BTNHIGHLIGHT),::GetSysColor(COLOR_BTNSHADOW)); else pDC->Draw3dRect(rect,::GetSysColor(COLOR_BTNSHADOW),::GetSysColor(COLOR_BTNHIGHLIGHT)); if (fUnderline.GetSafeHandle() == NULL) { CFont * pFont = GetFont(); ASSERT(pFont); LOGFONT lf; pFont->GetLogFont(&lf); lf.lfUnderline = TRUE; fUnderline.CreateFontIndirect(&lf); } pOldFont = pDC->SelectObject(&fUnderline); ReleaseDC(pDC); } void CLinkButton::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CRect rect1; GetWindowRect(rect1); CPoint ps; GetCursorPos(&ps); if(!rect1.PtInRect(ps)) { CButton::OnLButtonDown(nFlags, point); return; } m_updown=FALSE; /* CRect rect; GetClientRect(rect); CDC *pDC=GetDC(); pDC->Draw3dRect(rect,::GetSysColor(COLOR_BTNSHADOW),::GetSysColor(COLOR_BTNHIGHLIGHT)); ReleaseDC(pDC);*/ CButton::OnLButtonDown(nFlags, point); } void CLinkButton::OnLButtonUp(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CRect rect1; GetWindowRect(rect1); CPoint ps; GetCursorPos(&ps); if(!rect1.PtInRect(ps)) { CButton::OnLButtonDown(nFlags, point); return; } m_updown=TRUE; /* CRect rect; GetClientRect(rect); CDC *pDC=GetDC(); pDC->Draw3dRect(rect,::GetSysColor(COLOR_BTNHIGHLIGHT),::GetSysColor(COLOR_BTNSHADOW)); ReleaseDC(pDC); */ CButton::OnLButtonUp(nFlags, point); }